package com.example.webpractice.service;

import org.springframework.stereotype.Service;

@Service
public class CalcService {
    public int Calc(int a, int b, String op) {
        int c;
        switch (op) {
            case "+":
                c = a + b;
                break;
            case "-":
                c = a - b;
                break;
            case "*":
                c = a * b;
                break;
            case "/":
                if (b == 0) {
                    c = 0;
                    break;
                }
                c = a / b;
                break;
            case "min":
                c = Math.min(a, b);
                break;
            case "max":
                c = Math.max(a, b);
                break;
            case "pow":
                c = (int) Math.pow(a, b);
                break;
            default:
                c = 0;
        }
        return c;
    }
}
